﻿@model Models.OrderInfos
@{
    Layout = null;
    var s = ViewData["setting"] as List<Models.SystemSetting>;
    var cashs = ViewBag.Cash as List<Models.ItemList>;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>@ViewData["Title"]</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <environment include="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" media="all" />
        <link rel="stylesheet" href="~/layer/css/template.css" media="all" />
        <style>
            .media img {
                display: block;
                max-width: 100%;
                height: auto;
                /*margin-top: 10px;*/
            }
        </style>
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" asp-append-version="true" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" asp-append-version="true" media="all" />
        <link rel="stylesheet" href="~/layer/css/template.css" asp-append-version="true" media="all" />
        <style>
            .media img {
                display: block;
                max-width: 100%;
                height: auto;
                /*margin-top: 10px;*/
            }
        </style>
    </environment>
</head>
<body id="iosiframe">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space6">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div class="layui-form" action="" lay-filter="">
                            <div class="layui-form-item">
                                <div class="layui-col-lg12">
                                    <label class="layui-form-label">转账方式</label>
                                    <div class="layui-input-block">
                                        @foreach (var cash in cashs) {
                                            <input type="radio" value="@cash.value" id="Remittance" name="Remittance" title="@cash.text" lay-filter="radio">
                                        }
                                    </div>
                                </div>
                            </div>

                            <div id="divBank">
                                @if (s != null && s.Count > 0) {
                                    var name = s.FirstOrDefault(f => f.OtherType == ((int)Code.SystemType.收款人).ToString());
                                    var bank = s.FirstOrDefault(f => f.OtherType == ((int)Code.SystemType.收款银行).ToString());
                                    var account = s.FirstOrDefault(f => f.OtherType == ((int)Code.SystemType.收款账号).ToString());
                                    if (name != null) {
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">收款人</label>
                                            <div class="layui-form-mid">@name.Values</div>
                                        </div>
                                    }
                                    @if (bank != null) {
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">收款银行</label>
                                            <div class="layui-form-mid">@bank.Values</div>
                                        </div>
                                    }
                                    @if (account != null) {
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">收款卡号</label>
                                            <div class="layui-form-mid">@account.Values</div>
                                        </div>
                                    }
                                }
                            </div>

                            <div id="divAlipay" style="display:none;">
                                @if (s != null && s.Count > 0) {
                                    var alipay = s.FirstOrDefault(f => f.OtherType == ((int)Code.CashType.支付宝).ToString());
                                    if (alipay != null) {
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">收款人</label>
                                            <div class="layui-upload">
                                                <a href="javascript:;">
                                                    <img class="layui-upload-img" style="width:50%; height:50%" id="alipayImg" src="@alipay.Values">
                                                </a>
                                            </div>
                                        </div>
                                    }
                                }
                            </div>
                            <div id="divWechat" style="display:none;">
                                @if (s != null && s.Count > 0) {
                                    var wechat = s.FirstOrDefault(f => f.OtherType == ((int)Code.CashType.微信).ToString());
                                    if (wechat != null) {
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">收款人</label>
                                            <div class="layui-upload">
                                                <a href="javascript:;">
                                                    <img class="layui-upload-img" style="width:50%; height:50%" id="alipayImg" src="@wechat.Values">
                                                </a>
                                            </div>
                                        </div>
                                    }
                                }
                            </div>
                            @if ((Model.RemittanceImg + "").Length == 0) {
                                <div class="layui-form-item">
                                    <label class="layui-form-label">汇款凭证</label>
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="uploadimg">上传图片</button><input class="layui-upload-file" type="file" accept="undefined">
                                        <input type="hidden" name="RemittanceImg" id="RemittanceImg" />
                                    </div>
                                </div>
                                <div class="layui-form-item" id="layui_img" style="display:none;">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label"></label>
                                        <div class="layui-upload">
                                            <img class="layui-upload-img" width="200" height="200" id="test-upload-normal-img">
                                        </div>
                                    </div>
                                </div>
                            } else {
                                <div class="layui-form-item">
                                    <label class="layui-form-label">汇款凭证</label>
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="uploadimg">上传图片</button><input class="layui-upload-file" type="file" accept="undefined">
                                        <input type="hidden" name="RemittanceImg" id="RemittanceImg" value="@Model.RemittanceImg" />
                                    </div>
                                </div>
                                <div class="layui-form-item" id="layui_img">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label"></label>
                                        <div class="layui-upload">
                                            <img class="layui-upload-img" width="200" height="200" src="@Model.RemittanceImg" id="test-upload-normal-img">
                                        </div>
                                    </div>
                                </div>
                            }
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn  layui-btn-normal" lay-submit="" lay-filter="buy">确认</button>
                                    <a class="layui-btn  layui-btn-primary" href="@Url.Action("list","order")">取 消</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="~/layer/layui.js"></script>
    <script>
        layui.config({
            base: '../../layer/' //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['form', 'index', 'upload'], function () {
            var $ = layui.$
                , upload = layui.upload
                , form = layui.form;

            var ua = navigator.userAgent.toLowerCase();
            var screenwidth = window.screen.width;
            if (!/iphone|ipad|ipod/.test(ua)) {
                $("#iosiframe").attr("scrolling", "auto");
            } else {
                $('#iosiframe').width(screenwidth + 'px');
            }

            upload.render({
                elem: '#uploadimg'
                , url: '@Url.Action("filesave", "api")'
                , accept: 'images'
                , size: 2048
                , done: function (res, index, upload) {
                    if (res.code == 0) {
                        $('#RemittanceImg').val(res.data.src);
                        $('#test-upload-normal-img').attr('src', res.data.src);
                        $('#layui_img').show()
                    } else {
                        window.parent.tools.alert(res.msg);
                    }
                }
            });

            if ($('input[name="Remittance"]').html() != undefined) {
                cashInfo = $('input[name="Remittance"]:checked').val();

                if (cashInfo == undefined) {
                    $("input[name='Remittance']").get(0).click();

                    form.render('radio');
                }
            }

            form.on('radio(radio)', function (data) {
                if (data.value == 1) {
                    $('#divBank').show();
                    $('#divAlipay').hide();
                    $('#divWechat').hide();
                }
                else if (data.value == 2) {
                    $('#divBank').hide();
                    $('#divAlipay').show();
                    $('#divWechat').hide();
                }
                else {
                    $('#divBank').hide();
                    $('#divAlipay').hide();
                    $('#divWechat').show();
                }
            });

            form.on('submit(buy)', function (data) {
                var remittance = $('#Remittance').val()
                    , bank = $('#RemittanceBank').val()
                    , no = $('#RemittanceNo').val()
                    , img = $('#RemittanceImg').val();

                var loadindex = window.parent.tools.load(1, { shade: 0.8 });

                $.ajax({
                    url: '@Url.Action("saveremittance","api")',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify({ Id: @Model.Id, Remittance: remittance, RemittanceBank: bank, RemittanceNo: no, RemittanceImg: img }),
                    type: 'post'
                }).fail(function (jqXHR, textStatus, errorThrown) {
                    window.parent.tools.close(loadindex);
                    window.parent.tools.alert(errorThrown, { icon: 2, title: textStatus });
                }).done(function (res) {
                    window.parent.tools.close(loadindex);
                    window.parent.tools.alert(res.message, (res.code == 0 ? 1 : 2), function (index) {
                        if (res.code == 0) {
                            location.href = '@Url.Action("list","order")';
                        }
                    });
                });
            });
        });
    </script>
</body>
</html>
